#include<stdio.h>

#define BIT0	(0x01)
#define BIT1	(0x02)
#define BIT2	(0x04)
#define SET_SINAL_BIT(signal,bit)	signal = (signal | bit)
#define CLEAR_SINAL_BIT(signal,bit)	signal = (~bit) & signal
#define WAIT_BIT(signal,bit)		do{/*printf("wait\n")*/;}while(!(signal & BIT0));

unsigned char signal = 0;

int main()
{
	int index = 0;
	while(1){
		//TODO
		printf("set bit(0~3):");
		scanf("%d",&index);
		switch (index) {
		case 0:
			//TODO
			SET_SINAL_BIT(signal,BIT0);
			break;
		case 1:
			//TODO
			SET_SINAL_BIT(signal,BIT1);
			break;
		case 2:
			SET_SINAL_BIT(signal,BIT2);
			break;
		default:
			//TODO
			break;
		}
		WAIT_BIT(signal,BIT0);
//		printf("%02x\n",signal);
		if(signal & BIT0){
			printf("bit0\n");
			CLEAR_SINAL_BIT(signal,BIT0);
		}
			
		if(signal & BIT1){
			printf("bit1\n");
			CLEAR_SINAL_BIT(signal,BIT1);
			
		}
		
		if(signal & BIT2){
			printf("bit2\n");
			CLEAR_SINAL_BIT(signal,BIT2);
		}
			
	}
	
	return 0; 
}
